/*
 * Direction.java
 *
 * Created on 2007. m�rcius 25., 15:03
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package lemmings;

/**
 *
 * @author attila
 * A lemminget mozgat� oszt�ly
 */
public class Direction {
    
    private int direction;
    private Lemming owner;
    
    /** Konstruktor */
    public Direction(Lemming parent) {
        direction=3;
        owner=parent;
    }
    /**
     * Mozgatja a lemminget
     */
    public void action(Field f) {
        // Ez itt kurvara zavaros...
        if (!f.replaceLemming(owner,2)) {
            //System.out.println("@ ol�lo� 1");
            if (!owner.ground())
            if (!f.replaceLemming(owner, direction)) {
            //    System.out.println("@ ol�lo� 2");
                int old=direction;
            	direction=(direction==3)?1:3;
            	System.out.println("lemming_collide "+owner.getId()+" "+old+" "+direction);
            }
        }else{
          //  System.out.println("@ ol�lo� fall");
        	owner.fall();
          //  System.out.println("@ ol�lo� m�g megy");
        }
        
    }
    /**
     * Be�ll�tja az ir�nyt
     * @param d
     * A halad�si ir�ny 0:fel, 1:balra, 2: le, 3: le, 4: jobbra
     */
    public void setDirection(int d) {
        direction=d;
    }
}
